﻿using System.Collections.Generic;
using HMIS.FrameWork.Cache;
using HMIS.Infrastructure.Core.Authority;
using HMIS.Infrastructure.Core.Authority.Services;
using HMIS.Infrastructure.Core.Repositories;

namespace HMIS.Infrastructure.Facade.Authority.Impl
{
	public class AuthorityFacadeImpl : IAuthorityFacade
	{
		private readonly IHospUserRepository HospUserRepository;
		private readonly IMenuRepository MenuRepository;
		private readonly IActionPermissionRepository ActionPermissionRepository;
		private readonly ICache Cache;
		private readonly IAuthorityService AuthorityService;

		public AuthorityFacadeImpl(IHospUserRepository HospUserRepository, IMenuRepository MenuRepository, IActionPermissionRepository ActionPermissionRepository, ICache Cache, IAuthorityService AuthorityService)
		{
			this.HospUserRepository = HospUserRepository;
			this.MenuRepository = MenuRepository;
			this.ActionPermissionRepository = ActionPermissionRepository;
			this.Cache = Cache;
			this.AuthorityService = AuthorityService;
		}

		#region IAuthorityFacade 成员

		public bool Validate(string loginName, string pwd)
		{
			return HospUserRepository.Validate(loginName, pwd);
		}

		public bool ValidateById(string userId, string pwd)
		{
			return HospUserRepository.ValidateById(userId, pwd);
		}

		public HospUser GetHospUserByName(string loginName)
		{
			return HospUserRepository.GetByName(loginName);
		}

		public IList<MenuNode> GetMenusByUserId(string userId)
		{
			return MenuRepository.GetListByUserId(userId);
		}

		public IList<MenuNode> GetAllMenusByUserId(string userId)
		{
			return MenuRepository.GetAllListByUserId(userId);
		}

		public IList<ActionPermission> GetActionsByUserId(string userId)
		{
			return ActionPermissionRepository.GetListByUserId(userId);
		}

		public IList<ActionPermission> GetAllActionPermission()
		{
			return ActionPermissionRepository.GetAllActionPermissions();
		}

		public void ChangeUserPwd(string userId, string oldPwd, string newPwd)
		{
			AuthorityService.ChangeUserPwd(userId, oldPwd, newPwd);
		}
		#endregion
	}
}
